<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>收货地址管理</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
    <link rel="stylesheet" href="{{ url('/common/mobile-common/common.css') }}">
    <link rel="stylesheet" href="{{ url('mobile/css/member/address.css') }}">
    <script src="{{url('mobile/js/jquery-1.8.3.min.js')}}"></script>
    <script src="{{ url('/common/mobile-common/hmt.js') }}"></script>
</head>
<body>
<div class="abouts">
    <div class="wrap-cont clearfix">
        <!--地址列表-->
        <div class="wrap-cont address-show" style="display: block">
            @foreach($list as $v)
                <div class="address-list">
                    <p class="name-tel">{{ $v->name }}    {{substr_replace($v->phone,"****",3,4)}}
                    	<!--<i>默认</i>-->
                    </p>
                    <p>{{$v->province}}&nbsp{{$v->city}}&nbsp{{ $v->address }}</p>
                    <div>
                        <input type="radio" data-id="{{ $v->id }}" @if($v->sequence==1)checked="checked"@endif name="mr-address">
                        @if($v->sequence==1)
                        <img class="img" src="{{ url('mobile/images/check.png') }}">
                        <span class="mr">默认地址</span>
                        @else
                             <img class="img" src="{{ url('mobile/images/no-check.png') }}"> 
                            <span class="mr">设为默认</span>
                        @endif
                        <a>
                            <a href="{{url('wap/receiver/edit/'.$v->id)}}"><em class="edit-address">
                                    <i><img src="{{ url('mobile/images/bj-icon.png')}}">
                                    </i>编辑
                                </em></a>
                            <em class="del-address" data-id="{{ $v->id }}">
                                <i><img src="{{ url('mobile/images/sc-icon.png')}}">
                                </i>
                                删除
                            </em>
                        </a>
                    </div>
                </div>
            @endforeach
            <div class="opt-btn">
                <a href="{{url('wap/receiver/add')}}" class="add-btn">+新建地址</a>
            </div>
        </div>
        <!--end-->



    </div>
</div>
</body>
<script>
    $(function(){
        //选择收货地址页面默认地址切换
        $(".address-choice .address-list .fir-p i").hide();
        $(".address-choice .address-list .fir-p i").eq(0).show();
        $(".address-choice .address-list p input[type=radio]").click(function(){
            if($(this).attr("checked",true)){
                $(this).next().attr("src","{{ url('mobile/images/check.png') }}");
                 var mrIndex=$(this).parent().parent().index();
            $(".address-choice .address-list .fir-p i").hide();
            $(".address-choice .address-list").eq(mrIndex).find("i").show();
            }
           else{
             $(this).next().attr("src","{{ url('mobile/images/no-check.png') }}");
           }
           
        });
        $(".address-choice .gl-btn").click(function(){
        });
        //管理收货地址页面默认地址选择
        $(".address-list div input[type='radio']").click(function(){
        	var stasThis=$(this).parent().find(".mr").text();
        	if(stasThis=="设为默认"){
        		if(confirm("确认设为默认地址吗？")){
	              var _this = $(this);
	              $.ajax({
	                  type:'post',
	                  url:"{{ url('wap/receiver/setDefault') }}",
	                  data:{id:_this.data('id')},
	                  success:function(data) {
	                      if (data.success) {
	                          location.reload();
	                      }
	                  }
	              });
	          }
        	}
        	else if(stasThis=="默认地址"){
        		alert("已设为默认地址 ");
        	}
		});
        //管理收货地址页面删除地址
        $(".del-address").click(function(){
            var confir=confirm("确定删除地址吗?");
            if(confir){
                var _this = $(this);
                $.ajax({
                    type:'post',
                    url:"{{ url('wap/receiver/delete') }}",
                    data:{id:_this.data('id')},
                    success:function(data){
                        if(data.success){
                            location.reload();
                        }
                    }
                });
            }
        });
    })
</script>
</html>
